<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="留级学生" prop="student">
        <el-input
          v-model="queryParams.student"
          placeholder="请输入留级学生"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责老师" prop="dutyTeacher">
        <el-input
          v-model="queryParams.dutyTeacher"
          placeholder="请输入负责老师"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="困难系数" prop="difficultyNumber">
        <el-select v-model="queryParams.difficultyNumber" placeholder="请选择困难系数" clearable>
          <el-option
            v-for="dict in dict.type.sys_difficulty_coefficient"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="考试结果" prop="exam">
        <el-select v-model="queryParams.exam" placeholder="请选择考试结果" clearable>
          <el-option
            v-for="dict in dict.type.sys_end_test"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="模拟面试" prop="interview">
        <el-select v-model="queryParams.interview" placeholder="请选择模拟面试" clearable>
          <el-option
            v-for="dict in dict.type.sys_interview"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['teaching:repeate:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['teaching:repeate:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['teaching:repeate:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['teaching:repeate:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="repeateList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="留级学生" align="center" prop="students.name" />
      <el-table-column label="负责老师" align="center" prop="teachers.name" />
      <el-table-column label="所属班级" align="center" prop="bblClass.name" />
      <el-table-column label="困难系数" align="center" prop="difficultyNumber">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_difficulty_coefficient" :value="scope.row.difficultyNumber"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="考试结果" align="center" prop="exam">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_end_test" :value="scope.row.exam"/>
        </template>
      </el-table-column>
      <el-table-column label="模拟面试" align="center" prop="interview">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_interview" :value="scope.row.interview"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateTask(scope.row)"
            v-hasPermi="['teaching:repeate:edit']"
          >修改任务</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['teaching:repeate:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-share"
            @click="handLetrackRecord(scope.row)"
            v-hasPermi="['teaching:focuson:remove']"
          >跟踪记录</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-share"
            @click="handleDelete(scope.row)"
            v-hasPermi="['teaching:focuson:remove']"
          >移除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 修改留级学生任务对话框 -->
    <el-dialog :title="title" :visible.sync="task" width="500px" append-to-body>
      <el-form ref="form1" :model="form1" :rules="rules" label-width="80px">
        <el-form-item label="学生名字" prop="students.name">
          <el-input v-model="form1.student" disabled="false" placeholder="请输入留级学生" />
        </el-form-item>
        <el-form-item label="任务时间" prop="dutyTeacher">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker
              v-model="form1.taskTime"
              type="datetime"
              placeholder="选择日期时间"
              default-time="12:00:00">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item label="任务状态" prop="difficultyNumber">
          <el-select v-model="form1.taskType" placeholder="任务状态">
            <el-option
              v-for="dict in dict.type.sys_task_studenttype"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="任务说明" prop="remark">
          <el-input v-model="form1.remark" type="textarea" placeholder="请输入备注" />
        </el-form-item>
        <div style="text-align: -webkit-right">
          <el-button  type="primary" @click="addFrom1">确 定</el-button>
          <el-button @click="cancel">关闭任务</el-button>
        </div>
      </el-form>
      <!--   分割线 -->
      <el-divider ><i class="el-icon-mobile-phone"></i></el-divider>
      <!--   时间线组件    -->
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in modifyHistorys"
          :key="index"
          :color="colors(index)"
          type="primary"
          :timestamp="activity.createTime"
          placement="top">
          <el-card>
          <!--按键右移-->
            <el-form v-model="form2">
            <div style="text-align: -webkit-right">
              <el-form ref="ruleForm" label-width="100px" style="width: max-content">
                <el-form-item label-width="0">
                  <el-button @click="modifyHistory" >确认修改</el-button>
                </el-form-item>
              </el-form>
            </div>
              <h3>负责老师：{{activity.taskName }}</h3>
              <h3>任务说明：{{activity.taskContent }}</h3>
              <el-form-item label="任务状态" prop="difficultyNumber">
                  <el-select v-model="form2.finish" placeholder="任务状态">
                    <el-option
                      v-for="dict in dict.type.sys_task_studenttype"
                      :key="dict.value"
                      :label="dict.label"
                      :value="parseInt(dict.value)"
                    ></el-option>
                  </el-select>
              </el-form-item>
              <el-form-item label="完成说明">
                <el-input v-model="form2.finishContent"></el-input>
              </el-form-item>
            </el-form>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
    <!-- 跟踪记录 -->
    <el-dialog :title="title" :visible.sync="stalkeFormVisible">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in teachStalke"
          :key="index"
          :color="colors(index)"
          type="primary"
          :timestamp="activity.creationtime"
          placement="top">
          <el-card>
            <h1>我是你爹</h1>
            <h1>跟踪人的：{{activity.teachername}}</h1>
            <h3>问题说明：{{activity.remark}} </h3>
          </el-card>
        </el-timeline-item>
      </el-timeline>
      <div slot="footer" class="dialog-footer">
        <el-button @click="stalkeFormVisible = false">关闭</el-button>
      </div>
    </el-dialog>
     <!--修改模态框  -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="留级学生" prop="studentId">
          <el-select v-model="form.studentId" placeholder="请选择学生">
            <el-option
              v-for="dict in stuList"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="跟踪老师" prop="teacherId">
          <el-select v-model="form.teacherId" placeholder="请选择跟踪老师">
            <el-option
              v-for="dict in teachList"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="困难系数" prop="difficultyNumber">
          <el-select v-model="form.difficultyNumber" placeholder="请选择困难系数">
            <el-option
              v-for="dict in dict.type.sys_difficulty_coefficient"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="考试结果" prop="exam">
          <el-select v-model="form.exam" placeholder="请选择考试结果">
            <el-option
              v-for="dict in dict.type.sys_end_test"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模拟面试" prop="interview">
          <el-select v-model="form.interview" placeholder="请选择模拟面试">
            <el-option
              v-for="dict in dict.type.sys_interview"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-button  type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel1">取消</el-button>
    </el-dialog>
  </div>
</template>
<!--  lbj-->
<script>
import {  listRepeate,getTaskData, getRepeate, delRepeate, addRepeate, updateRepeate } from "@/api/teaching/repeate";
import {
  getfindListmodifyHistorys,
  getfindListByStudentId,
  gettaskupdate,
  getStu,
  getteacher
} from "@/api/teaching/stalke";

export default {
  name: "Repeate",
  dicts: ['sys_task_studenttype','sys_end_test', 'sys_difficulty_coefficient', 'sys_interview','sys_job_status'],
  data() {
    return {
      teachList :[],
      // 追踪记录
      teachStalke:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 留级学生名单表格数据
      repeateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        student: null,
        dutyTeacher: null,
        difficultyNumber: null,
        exam: null,
        interview: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 跟踪弹框是否弹出
      stalkeFormVisible:false,
      // 修改任务弹出框
      task:false,
      // 修改任务的表单
      form1: {
        student: '',
        taskTime:'',
        remark:'',
        taskType:'',
      },
      // 历史任务的修改
      form2: {
        taskType:'',
        taskContent:'',
        mytaskId: '',
        finishContent:'',
        finish:'',
      },
      modifyHistorys:[]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 修改历史任务
    modifyHistory(){
      let params = this.form2
      gettaskupdate(params).then(res => {
        this.modifyHistorys = res.data
        alert("修改成功！")
      })
      this.task = false
      this.resetForm("form2");
    },
    /** 添加任务*/
    addFrom1(){
      let parems = this.form1;
      getTaskData(parems).then(response => {
        this.form1 = response.data;
      });
       this.task = false;
       alert("修改成功！")
    },


    /** 查询留级学生名单列表 */
    getList() {
      this.loading = true;
      listRepeate(this.queryParams).then(response => {
        this.repeateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消修改任务按钮
    cancel() {
      this.task = false;
      this.reset();
    },
    // 取消修改按钮
    cancel1() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        student: null,
        dutyTeacher: null,
        difficultyNumber: null,
        remark: null,
        exam: null,
        interview: null,
        studentId: null,
        teacherId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加留级学生名单";
    },
    /** 修改任务按钮操作 */
    handleUpdateTask(row) {
      this.reset();
      this.title = "修改留级学生名单";
      this.task = true;
      this.form1={
        student: row.students.name,
        taskTime:'',
        remark:'',
        taskType:'',
        id:row.id,
        mytaskId:row.mytaskId,
        teacherId:row.teacherId
      };
      console.log(row.students.name)
      getfindListmodifyHistorys(row.students).then(res => {
        this.modifyHistorys = res.data
        this.modifyHistorys.forEach((item, index, arr) => {
          this.form2.finish = item.finish
          this.form2.finishContent = item.finishContent
          this.form2.mytaskId = item.id
        })
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRepeate(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改留级学生名单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRepeate(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRepeate(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除留级学生名单编号为"' + ids + '"的数据项？').then(function() {
        return delRepeate(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('teaching/repeate/export', {
        ...this.queryParams
      }, `repeate_${new Date().getTime()}.xlsx`)
    },
    /** 跟踪记录*/
    handLetrackRecord(row){
      let name = row.student
      this.stalkeFormVisible=true;
      this.title = "【"+name+"】的跟踪历史"
      getfindListByStudentId(row.studentId).then(res => {
        this.teachStalke = res.data
      })
    },
    /**根据下标选颜色*/
    colors(index){
      if (index % 2 == 0){
        return '00D6FDFF'
      } else {
        return 'D81E1EFF'
      }
    },
    /** 获得学生的全部*/
    getstuList(){
      getStu().then(response =>{
        this.stuList = response.rows
      })
    },
    /** 获得老师的全部*/
    getTeacherList(){
      getteacher().then(response =>{
        this.teachList = response.data
      })
    }
  },
  mounted() {
    this.getstuList();

    this.getTeacherList();
  }
};
</script>


